import openpyxl
import re
workbook = openpyxl.load_workbook('test1.xlsx')

sheet = workbook["Sheet2"]
# 获取最大列数
maxColumn = sheet.max_column
print('最大列',maxColumn)
max_row=sheet.max_row
print('最大行',max_row)

settmp=set()
a=0
for one_column_data in sheet.iter_rows():
    a = a+1
    strmsg=one_column_data[0].value
    #print(strmsg)
    #print(a)
    #print("=======================================================")
    if isinstance(strmsg, str):
        while (strmsg.find("##{") != -1):
            if strmsg.find("##{") > strmsg.find("#{"):
                #print("----")
                strStartindex = strmsg.find("#{")
                strEndindex = strmsg.find("}")
                settmp.add(strmsg[strStartindex+2:strEndindex ])
                # if strmsg[strStartindex+2:strEndindex].find("stat") != -1:
                #     print(strmsg)
                # print(strmsg[strStartindex:strEndindex + 1])
                strmsg = strmsg.replace(strmsg[strStartindex:strEndindex + 1], '')
            else:
                #print("======")
                strStartindex = strmsg.find("##{")
                strEndindex = strmsg.find("}")
                print(strmsg[strStartindex:strEndindex + 1])
                strmsg = strmsg.replace(strmsg[strStartindex:strEndindex + 1], '')

        while (strmsg.find("#{") != -1):
            #print("----")
            strStartindex = strmsg.find("#{")
            strEndindex = strmsg.find("}")
            settmp.add(strmsg[strStartindex + 2:strEndindex])
            # if strmsg[strStartindex + 2:strEndindex].find("stat") != -1:
            #     print(strmsg)
            # print(strmsg[strStartindex:strEndindex + 1])
            strmsg = strmsg.replace(strmsg[strStartindex:strEndindex + 1], '')



print(len(settmp))
for tmpName in settmp:
    print(" String "+tmpName+" = \""+tmpName+"\";")
    #
    # if isinstance(strmsg, str) and strmsg.find("##{")!=-1:
    #     strStartindex=strmsg.find("##{")
    #     strEndindex=strmsg.find("}")
    #     # print(strStartindex)
    #     # print(strEndindex)
    #     # print(strmsg[strStartindex+2:strEndindex])
    #     result=strmsg.replace(strmsg[strStartindex:strEndindex+1],'')
    #     print(result)
    #     #完整带#{}
    #     #print(strmsg[strStartindex:strEndindex+1])




        # for tmp in strmsg:
        #     if tmp == "{":
        #         print(tmp)

